//
//  YCFriendHomeViewController.m
//  YCSchool
//
//  Created by gmall on 16/5/13.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//

#import "YCFriendHomeViewController.h"
#import <FXBlurView/FXBlurView.h>


@interface YCFriendHomeViewController ()<XHImageViewerDelegate>

/** 头像大背景  */
@property (nonatomic, strong) UIImageView *contentImageView;
/// 导航条右上角...
@property (nonatomic,readonly) UIButton *rightMoreButton;
/// 头像小背景
@property (nonatomic,readonly) UIImageView *iconBgImageView;
/// 头像
@property (nonatomic,readonly) UIImageView *iconImageView;
/// 昵称+星座
@property (nonatomic,readonly) UILabel *nickerAstroLabel;
/// 地址
@property (nonatomic,readonly) UILabel *placeLabel;
/// 加好友
@property (nonatomic,readonly) UIButton *addFriendButton;
/** 底部条  */
@property (nonatomic, strong) UIView *bottomView;

/** <#标注名称#>  */
@property (nonatomic, strong) NSMutableArray *photoArray;

@end

@implementation YCFriendHomeViewController

@synthesize contentImageView = _contentImageView;
@synthesize rightMoreButton = _rightMoreButton;
@synthesize nickerAstroLabel = _nickerAstroLabel;
@synthesize placeLabel = _placeLabel;
@synthesize iconBgImageView = _iconBgImageView;
@synthesize iconImageView = _iconImageView;
@synthesize addFriendButton = _addFriendButton;
@synthesize bottomView = _bottomView;



#pragma mark - 懒加载

- (NSMutableArray *)photoArray
{
    if (!_photoArray) {
        _photoArray = [NSMutableArray array];
    }
    return _photoArray;
}

/// 导航条右边按钮
- (UIButton *)rightMoreButton
{
    if(!_rightMoreButton)
    {
        _rightMoreButton = [[UIButton alloc] init];
        _rightMoreButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        [_rightMoreButton setImage:[UIImage imageNamed:@"nav_More_white"] forState:UIControlStateNormal];
        [_rightMoreButton addTarget:self action:@selector(didTouchUpInsideRightMoreButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightMoreButton;
}


// 昵称与星座
- (UILabel *)nickerAstroLabel
{
    if(!_nickerAstroLabel)
    {
        _nickerAstroLabel = [[UILabel alloc] init];
        _nickerAstroLabel.text = @"Leelan 狮子座";
        _nickerAstroLabel.textColor = [UIColor yc_colorWithUInt:0xffffff alpha:0.8];
        _nickerAstroLabel.textAlignment = NSTextAlignmentCenter;
        _nickerAstroLabel.font = [UIFont systemFontOfSize:15];
    }
    return _nickerAstroLabel;
}

// 地址
- (UILabel *)placeLabel
{
    if(!_placeLabel)
    {
        _placeLabel = [[UILabel alloc] init];
        _placeLabel.text = @"广东 广州";
        _placeLabel.textColor = [UIColor yc_colorWithUInt:0xffffff alpha:0.8];
        _placeLabel.textAlignment = NSTextAlignmentCenter;
        _placeLabel.font = [UIFont systemFontOfSize:13];
    }
    return _placeLabel;
}
// 头像
- (UIImageView *)iconImageView
{
    if(!_iconImageView)
    {
        _iconImageView = [[UIImageView alloc] init];
        //        _iconImageView.image = [UIImage imageNamed:@"选择相册"];
        _iconImageView.image = [UIImage imageNamed:@"mf_bg_img"];
        __block CGFloat width = 0;
        [YCAdapter performOtherBlock:^{
            width = 165;
        } IPhone6Block:^{
            width = 195;
        } IPhone6pBlock:^{
            width = 205;
        }];
        _iconImageView.layer.cornerRadius = width / 2.0;
        _iconImageView.layer.masksToBounds = YES;
        _iconImageView.userInteractionEnabled = YES;
        _iconImageView.contentMode = UIViewContentModeScaleAspectFill;
        
        UITapGestureRecognizer *tapIcon = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapIcon:)];
        [_iconImageView addGestureRecognizer:tapIcon];
        [self.photoArray addObject:_iconImageView];
    }
    return _iconImageView;
}

// 头像背景
- (UIImageView *)iconBgImageView
{
    if(!_iconBgImageView)
    {
        _iconBgImageView = [[UIImageView alloc] init];
        _iconBgImageView.image = [UIImage imageNamed:@"头像框"];
        _iconBgImageView.userInteractionEnabled = YES;
        _iconBgImageView.layer.masksToBounds = YES;
        __block CGFloat width = 0;
        [YCAdapter performOtherBlock:^{
            width = 190;
        } IPhone6Block:^{
            width = 232;
        } IPhone6pBlock:^{
            width = 240;
        }];
        _iconBgImageView.layer.cornerRadius = width / 2.0;
        _iconBgImageView.contentMode = UIViewContentModeScaleAspectFill;
        _iconBgImageView.clipsToBounds = YES;
    }
    return _iconBgImageView;
}

- (UIButton *)addFriendButton
{
    if (!_addFriendButton) {
        _addFriendButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _addFriendButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_addFriendButton setTitle:@"加为好友" forState:UIControlStateNormal];
        [_addFriendButton setTitleColor:[UIColor yc_colorWithUInt:0xffffff alpha:0.5] forState:UIControlStateNormal];
        _addFriendButton.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        _addFriendButton.layer.cornerRadius = 17.5;
        _addFriendButton.layer.masksToBounds = YES;
        [_addFriendButton addTarget:self action:@selector(didTouchUpInsideAddFriendButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _addFriendButton;
}

- (UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight-49,kScreenWidth,49)];
        _bottomView.backgroundColor = [UIColor whiteColor];
        UIButton *backBtn = [[UIButton alloc] init];
        [backBtn setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
        backBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -17, 0, 0);
        [backBtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_bottomView addSubview:backBtn];
    
        [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_bottomView);
            make.top.bottom.equalTo(_bottomView);
            make.width.equalTo(@55);
        }];
        
    }
    return _bottomView;
}


#pragma mark - 生命周期

- (void)viewDidLoad {
    [super viewDidLoad];

    [self makeView];
    
}

- (void)makeView
{
    
    UIImageView *contentImageView = [[UIImageView alloc] init];
    contentImageView.backgroundColor = [UIColor yc_colorWithUInt:0xf7f7f7];
    contentImageView.image = [UIImage imageNamed:@"mf_bg_img"];
    contentImageView.userInteractionEnabled = YES;
    //模糊效果
    FXBlurView * aview = [[FXBlurView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    aview.tintColor = [UIColor clearColor];  //前景颜色
    aview.blurRadius = 10;                 //模糊半径，View的模糊效果程度
    [contentImageView addSubview:aview];
    self.contentImageView = contentImageView;
    [self.view addSubview:contentImageView];
    [self.contentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
//        make.bottom.equalTo(self.bottomView.mas_top);
    }];
    
    [self.view addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.height.equalTo(@49);
    }];
    
    [self.contentImageView addSubview:self.rightMoreButton];
    [self.contentImageView addSubview:self.iconBgImageView];
    [self.contentImageView addSubview:self.iconImageView];
    [self.contentImageView addSubview:self.nickerAstroLabel];
    [self.contentImageView addSubview:self.placeLabel];
    [self.contentImageView addSubview:self.addFriendButton];


    [self.rightMoreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_contentImageView).offset(30);
        make.right.equalTo(_contentImageView).offset(-15);
        make.height.equalTo(@15);
    }];
    
    [_iconBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_contentImageView).offset(heightFromIphone6Height(93));
        make.centerX.equalTo(self.contentImageView);
        [YCAdapter performOtherBlock:^{
            make.width.height.equalTo(@190);
        } IPhone6Block:^{
            make.width.height.equalTo(@232);
        } IPhone6pBlock:^{
            make.width.height.equalTo(@240);
        }];
    }];
    
    [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        [YCAdapter performOtherBlock:^{
            make.width.height.equalTo(@165);
        } IPhone6Block:^{
            make.width.height.equalTo(@195);
        } IPhone6pBlock:^{
            make.width.height.equalTo(@205);
        }];
        make.center.equalTo(_iconBgImageView);
    }];
    
    [_nickerAstroLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_iconBgImageView.mas_bottom).offset(heightFromIphone6Height(22));
        make.centerX.equalTo(_iconBgImageView);
        make.height.equalTo(@15);
    }];
    
    [_placeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nickerAstroLabel.mas_bottom).offset(heightFromIphone6Height(11));
        make.centerX.equalTo(_iconBgImageView);
        make.height.equalTo(@13);
    }];
    
    
    [_addFriendButton mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerX.equalTo(self.contentImageView);
        make.width.equalTo(@200);
        make.height.equalTo(@35);
        make.bottom.equalTo(self.contentImageView).offset(-60-49);
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



#pragma mark - 点击事件

// 右边
- (void)didTouchUpInsideRightMoreButton:(UIButton *)button
{
    YCLogFunc

}


// 添加好友
- (void)didTouchUpInsideAddFriendButton:(UIButton *)button
{
    YCLogFunc
}

// 退出
- (void)backBtnClick:(UIButton *)button
{
    YCLogFunc
    [self dismissViewControllerAnimated:YES completion:nil];
}

// 点击预览大图
- (void)tapIcon:(UITapGestureRecognizer *)gesture
{
    UIImageView *imageView = (UIImageView *)gesture.view;
    YCLogFunc
    
    UIImageView * imgv =[[UIImageView alloc]initWithFrame:imageView.layer.bounds];
    imgv.userInteractionEnabled =YES;
    imgv.contentMode = UIViewContentModeScaleAspectFill;
    imgv.clipsToBounds = YES;
    imgv.image = imageView.image;
    [imageView addSubview:imgv];
    
    XHImageViewer *imageViewer = [[XHImageViewer alloc] init];
    imageViewer.delegate = self;
    [imageViewer showWithImageViews:@[imgv] selectedView:imgv];
    
}

#pragma mark -
- (void)imageViewer:(XHImageViewer *)imageViewer  willDismissWithSelectedView:(UIImageView*)selectedView
{
    YCLogFunc;
}

- (UIView *)customBottomToolBarOfImageViewer:(XHImageViewer *)imageViewer
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight - 49, kScreenWidth, 49)];
    view.backgroundColor = [UIColor whiteColor];
    return view;
}

@end
